package com.xyzh.stj.web.service.impl;

import com.xyzh.stj.web.entity.UserOrganizationEntity;
import com.xyzh.stj.web.dao.UserOrganizationMapper;
import com.xyzh.stj.web.service.UserOrganizationService;
import com.xyzh.application.base.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户机构表 服务实现类
 * </p>
 *
 * @author @JZB
 * @since 2023-10-29
 */
@Service
public class UserOrganizationServiceImpl extends BasicServiceImpl<UserOrganizationMapper, UserOrganizationEntity> implements UserOrganizationService {
    @Override
    public int addOrganizations(String userId, List<String> orgs) {
        UserOrganizationEntity delUserOrg=new UserOrganizationEntity();
        delUserOrg.setUserid(userId);
        this.deleteEntityNotId(delUserOrg);
        int count = 0;
        for (String org : orgs) {

            UserOrganizationEntity userOrganizationEntity = new UserOrganizationEntity();
            userOrganizationEntity.setUserid(userId);
            userOrganizationEntity.setOrganizationid(org);
            boolean t = this.saveEntity(userOrganizationEntity);
            if (t) {
                count++;
            }
        }
        return count;

    }

    @Override
    public boolean deleteEntity(UserOrganizationEntity entity) {
        return super.deleteEntityNotId(entity);
    }
}
